package com.lg.concurrent.atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class AtomicReferenceFieldUpdaterTest {

    public static AtomicReferenceFieldUpdater updater = AtomicReferenceFieldUpdater.newUpdater(Student.class, Integer.class, "score");
    public static Student student = new Student();

    public static void main(String[] args) {
        System.out.println("获取指定对象的指定属性值：" + updater.get(student));

        System.out.println(updater.compareAndSet(student,128,99));;

//        System.out.println(updater.compareAndSet(student,127,99));;
        System.out.println("执行compareAndSet 后指定对象的指定属性值：" + updater.get(student));

        updater.set(student,2000);
        System.out.println("执行set(student,2000)后指定对象的指定属性值：" + updater.get(student));

        updater.updateAndGet(student,(s1)->(1001));
        System.out.println("执行updateAndGet(student,(s1)->(1001))后指定对象的指定属性值：" + updater.get(student));
    }
}

class Student {
    public volatile Integer score = 128;
}